package com.dzm.thirdpart.controller;

import com.dzm.thirdpart.service.GiteeService;
import com.ruoyi.common.core.web.domain.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.Map;

/**
 * 作者：Dzm
 * 时间：2024-09-14-12:37
 * 功能：
 */

@Controller
@RequestMapping
public class GiteeController {

    @Autowired
    private GiteeService giteeService;

    @GetMapping("/gitee/callback/success")
    public String giteLogin(@RequestParam("code")String code, HttpSession session) {
        Map<String, String> userInfo = giteeService.getUserInfo(code);

        String redirectUrl = (String) session.getAttribute("redirectUrl");
        //将用户信息放入session
        session.setAttribute("name", userInfo.get("login"));
        return "redirect:" + redirectUrl;
    }
}
